package com.roc.web.action.terminal;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.PaginationBaseAction;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
/**
 * 终端统计
* @Title: TerminalStatisticsSearchCondition.java 
* @Package com.roc.web.action.terminal 
* @Description: TODO 
* @author dk
* @version V1.0
 */
public class TerminalStatisticsSearchCondition extends BaseSearchCondition {
	
	private String 	minDate; // 交易开始时间(年月日)
	private String 	maxDate; // 交易结束时间(年月日)
	private String  agentId;//分公司
	private String 	directId;//直属代理
	private String  serialNum;//sn序列号
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
		if (Constance.isNotEmpty(minDate))
		{
			filedBeanList.add(new WhereHQLFieldBean("TO_CHAR(p.dt_lastmod, 'yyyyMMdd')", minDate.trim(), ">=", false));
		}
		if (Constance.isNotEmpty(maxDate))
		{
			filedBeanList.add(new WhereHQLFieldBean("TO_CHAR(p.dt_lastmod, 'yyyyMMdd')", maxDate.trim(), "<=", false));
		}
		if (Constance.isNotEmpty(serialNum))
		{
			filedBeanList.add(new WhereHQLFieldBean("p.serial_num", serialNum.trim(), "=", false));
		}
		if(Constance.isNotEmpty(agentId))
		{
			filedBeanList.add(new WhereHQLFieldBean("p.companyid", agentId, "=", false));
		}
		if(Constance.isNotEmpty(directId))
		{
			filedBeanList.add(new WhereHQLFieldBean("p.oneagentid",directId, "=", false));
		}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer sb=new StringBuffer();
		sb.append(" select count(*) from (select (select real_name from t_operators s where s.id = b.companyid) as name1, "
				+ " (select real_name from t_operators s where s.id = b.oneagentid) as name2,"
				+ " m.serial_num, n.mcht_cd,n.term_id,m.dt_lastmod,b.companyid,b.oneagentid from yj_pos_info m,"
				+ " tbl_term_inf n,tbl_mcht_inf a,t_operators b where m.serial_num = n.device_cd and m.pos_brand=n.tmnl_brand "
				+ " and m.is_bind = 'Y' and substr(m.serial_num,0,2)<>'YJ' and a.mcht_cd=n.mcht_cd  and to_number(a.ext1)=b.id ) p where 1=1 ");
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer sb=new StringBuffer();
		sb.append(" select nvl(name1,'-'),nvl(name2,'-'),mcht_cd,term_id,serial_num,dt_lastmod from (select (select real_name from t_operators s where s.id = b.companyid) as name1, "
				+ " (select real_name from t_operators s where s.id = b.oneagentid) as name2,"
				+ " m.serial_num,n.mcht_cd,n.term_id,m.dt_lastmod,b.companyid,b.oneagentid from yj_pos_info m,"
				+ " tbl_term_inf n,tbl_mcht_inf a,t_operators b where m.serial_num = n.device_cd and m.pos_brand=n.tmnl_brand "
				+ " and m.is_bind = 'Y' and substr(m.serial_num,0,2)<>'YJ' and a.mcht_cd=n.mcht_cd  and to_number(a.ext1)=b.id ) p where 1=1 ");
		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		return " order by p.name1,p.name2 ";
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getDirectId() {
		return directId;
	}

	public void setDirectId(String directId) {
		this.directId = directId;
	}

	public String getSerialNum() {
		return serialNum;
	}

	public void setSerialNum(String serialNum) {
		this.serialNum = serialNum;
	}
		
}
